#pragma once
//============================================================================
// Copyright (C) 2009-2013 Brett R. Jones
//
// Issued to public domain 2013
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================
#define LOG_PRIORITY_MASK	0x000000ff
#define LOG_MODULE_MASK		0xfffffe00

#define LOG_VERBOSE (0x0001)
#define LOG_FATAL	(0x0002)
#define LOG_SEVERE	(0x0004)
#define LOG_ASSERT	(0x0008)
#define LOG_ERROR	(0x0010)
#define LOG_WARN	(0x0020)
#define LOG_INFO	(0x0040)
#define LOG_DEBUG	(0x0080)

#define LOG_SKT		(LOG_DEBUG | 0x0200)
#define LOG_JNI		(LOG_DEBUG | 0x0400)
#define LOG_TEST	(LOG_DEBUG | 0x0800)
#define LOG_PKT	    (LOG_DEBUG | 0x1000)
#define LOG_THREAD	(LOG_DEBUG | 0x2000)


#define MAX_ERR_MSG_SIZE 2048

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*LOG_FUNCTION )( unsigned long, char * );

//! set function that logs a message
void set_log_handler( LOG_FUNCTION pfuncLogHandler );

//! log a message
void log_msg( unsigned long u32MsgType, const char* msg, ...);

void set_log_to_file( const char * pFileName );
void set_log_flags( unsigned long u32LogFlags );

#ifdef _DEBUG
	/// This function is called by vx_assert() when the assertion fails.
	void  vx_error_output( unsigned long u32LogLevel, char* exp, char * file, int line);
	// debug mode throws message if expression is false

	#define vx_assert(exp) { if (!(exp)) vx_error_output(LOG_ASSERT,(char*)#exp,(char*)__FILE__,__LINE__); }
	#define vx_verify(exp) { if (!(exp)) vx_error_output(LOG_ASSERT,(char*)#exp,(char*)__FILE__,__LINE__); }
	#define vx_fatal(exp) { if (!(exp)) vx_error_output(LOG_FATAL,(char*)#exp,(char*)__FILE__,__LINE__); }
	//#define VxVerifyCodePtr(exp) VxCheckForValidCodePtr(exp)

#else
	// release mode evaluates vx_assert ect to null
	#define vx_assert(exp)
	#define vx_verify(exp) (exp)
	#define vx_fatal(exp) (exp)
	//#define VxVerifyWritePtr(exp)

#endif // RELEASE_MODE

//! check for valid pointer
//void VxCheckForValidCodePtr( void * pvPtr );
//void VxCheckForValidReadPtr( void * pvPtr );
//void VxCheckForValidWritePtr( void * pvPtr );

#ifdef __cplusplus
}
#endif


